#ifndef __DomainSocket_h__
#define __DomainSocket_h__

#include <base/types.h>
#include "IpSocket.h"

#include <string>

namespace Greatewall
{
    namespace Network
    {
        class DomainSocket : public IpSocket
        {
        public:
            enum DomainSockMode
            {
                CLIENT,
                CLIENT_HANDLER,
                SERVER
            };

            DomainSocket(SocketEventMonitor& monitor, SysSockHandler hdl = -1)
                : IpSocket(monitor, hdl)
            {}

            virtual ~DomainSocket()
            {}

            virtual void
            handleInbound() = 0;

            virtual bool
            handleOutbound() = 0;

            virtual bool
            send(const char* buf, ssize_t& size, bool non_block = true);

            virtual bool
            recv(char*& buf, ssize_t& size, bool non_block = true);

            static SysSockHandler
            createDomainSock();

            bool
            initDomainSock(std::string& sock_path, DomainSockMode mode, int backlog = 10);

            bool
            initDomainSock(SysSockHandler hdl, std::string& sock_path);

            virtual void
            close();

        private:
            std::string    _sock_path;
            DomainSockMode _mode;
        };
    }
}
#endif
